
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;

import javax.swing.JPanel;
import javax.swing.JFrame;

import java.util.Random;


public class Map extends JPanel {
	
	private int width;
	private int height;
	private int edgeX, edgeY;
	private final double rate = 0.01;
	private ListOfPoints list;
	private double minla, maxla, minlo, maxlo;
	private int w, h;
	
	
	public Map(double minla, double maxla, double minlo, double maxlo) {
		width = 600;
		height = 600;
		edgeX = (int) (width * rate);
		edgeY = (int) (height * rate);
		double sizeLa = (maxla - minla) / 10.0;
		double sizeLo = (maxlo - minlo) / 10.0;
		
		this.minla = minla; //+ sizeLa * 0.5; 
		this.maxla = maxla; //- sizeLa * 8.5;
		this.minlo = minlo; //+ sizeLo * 4.0;
		this.maxlo = maxlo; //- sizeLo * 5.0;
	    Insets insets = getInsets();
	      
	    w =  width - insets.left - insets.right;
	    h =  height - insets.top - insets.bottom;
	}
	
	
	
	public int getWidth() {
		return width;
	}



	public void setWidth(int width) {
		this.width = width;
	}



	public int getHeight() {
		return height;
	}



	public void setHeight(int height) {
		this.height = height;
	}



	public void setList(ListOfPoints list) {
		this.list = list;
	}



	private int[] getLocation(Point point) {
		int[] returnValues = new int[2];
		if(point.getLatitude() > maxla || point.getLatitude() < minla || point.getLongtitude() > maxlo || point.getLongtitude() < minlo) {
			returnValues[0] = returnValues[1] = 0;
			return returnValues;
		} else {
			double scaleX = (point.getLatitude() - minla) / (maxla - minla);
			returnValues[0] = (int) (scaleX * w);
			
			double scaleY = (point.getLongtitude() - minlo) / (maxlo - minlo);
			returnValues[1] = (int) (scaleY * h);
			
			return returnValues;
		}
		
	}

	public void paintComponent(Graphics g) {
      super.paintComponent(g);

      Graphics2D g2d = (Graphics2D) g;

      g2d.setColor(Color.red);

      for (int i=0; i<list.numberOfPoints(); i++) {
    	  int[] value = getLocation(list.getPoint(i));
    	  g2d.drawOval(value[0], value[1], edgeX, edgeY);
      }
  }
}